package com.roadjava.javaweb.student.service.impl;

import com.roadjava.javaweb.student.beans.entity.StudentDO;
import com.roadjava.javaweb.student.beans.req.StudentRequest;
import com.roadjava.javaweb.student.beans.res.ResultDTO;
import com.roadjava.javaweb.student.beans.res.TableResult;
import com.roadjava.javaweb.student.beans.vo.StudentVO;
import com.roadjava.javaweb.student.dao.StudentDao;
import com.roadjava.javaweb.student.dao.impl.StudentDaoImpl;
import com.roadjava.javaweb.student.service.StudentService;

import java.util.List;


public class StudentServiceImpl implements StudentService {
    private StudentDao studentDao = new StudentDaoImpl();
    @Override
    public boolean addStudent(StudentDO studentDO) {
        return studentDao.addStudent(studentDO) == 1;
    }

    @Override
    public TableResult<StudentVO> queryStudentByPage(StudentRequest studentRequest) {
        return studentDao.queryStudentByPage(studentRequest);
    }

    @Override
    public StudentVO getStudentById(long studentId) {
        return studentDao.getStudentById(studentId);
    }

    @Override
    public boolean updateStudent(StudentDO studentDO) {
        return studentDao.updateStudent(studentDO) == 1;
    }

    @Override
    public boolean deleteStudentById(long studentId) {
        return studentDao.deleteStudentById(studentId) == 1;
    }

    @Override
    public ResultDTO<List<StudentVO>> loadAllStudents() {
        List<StudentVO> studentVOS = studentDao.loadAllStudents();
        return ResultDTO.buildSuccess(studentVOS);
    }
}
